//
//  ShareOpenResoureTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/6/18.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ShareOpenResoureTableViewCell.h"

@interface ShareOpenResoureTableViewCell ()
/**  图片   */
@property (strong, nonatomic) UIImageView  *actImageView;
/**  标题  */
@property (strong, nonatomic) UILabel  *actLabel;
/** 状态 */
@property (nonatomic, strong) UILabel *typeLabel;
/**  时间图片  */
@property (strong, nonatomic) UIImageView  *timeImageVIew;
/**  时间  */
@property (strong, nonatomic) UILabel  *timeLabel;
/**  人数  */
@property (strong, nonatomic) UILabel  *actNumberLabel;
/**  地点  */
@property (strong, nonatomic) UILabel  *addressLabel;
/**  地点图片  */
@property (strong, nonatomic) UIImageView  *addressImageView;
/**  活动状态  */
@property (strong, nonatomic) UILabel  *statusLabel;



@end
@implementation ShareOpenResoureTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
        
        
        TenGrayShadowView *under = [TenGrayShadowView new];
        under.backgroundColor = [UIColor themeGrayColor];
        [self addSubview:under];
        under.sd_layout.bottomEqualToView(self).heightIs(10 * [UIScreen zj_screenHScale]).widthIs([UIScreen zj_screenWith]).leftEqualToView(self);
    }
    return self;
}





#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.actImageView];
    //    [self addSubview:self.addressImageView];
    [self addSubview:self.addressLabel];
    [self.actImageView addSubview:self.statusLabel];
    [self addSubview:self.typeLabel];
    //    [self addSubview:self.timeImageVIew];
    [self addSubview:self.timeLabel];
    [self addSubview:self.actNumberLabel];
    [self addSubview:self.actLabel];
    
    
    self.actImageView.sd_layout
    .topSpaceToView(self,10 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self,12 * [UIScreen zj_screenWScale])
    .heightIs(90 * [UIScreen zj_screenHScale])
    .widthIs(130 * [UIScreen zj_screenWScale]);
    
    self.actLabel.sd_layout
    .topEqualToView(self.actImageView)
    .leftSpaceToView(self.actImageView,10 * [UIScreen zj_screenWScale])
    .heightIs(17 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
    self.addressLabel.sd_layout
    .bottomEqualToView(self.actImageView)
    .leftSpaceToView(self.actImageView,10 * [UIScreen zj_screenWScale])
    .heightIs(12 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
    
    self.statusLabel.sd_layout
    .topEqualToView(self.actImageView)
    .leftEqualToView(self.actImageView)
    .heightIs(25 * [UIScreen zj_screenHScale])
    .widthIs(23 * [UIScreen zj_screenWScale]);
    [self.statusLabel setRadius:10 byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight];
    
    self.timeLabel.sd_layout
    .topSpaceToView(self.actLabel, 5 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.addressLabel)
    .heightIs(12 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
    self.actNumberLabel.sd_layout
    .bottomSpaceToView(self.addressLabel,5 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.timeLabel)
    .heightIs(15 * [UIScreen zj_screenHScale])
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
    self.typeLabel.sd_layout
    .bottomSpaceToView(self.actNumberLabel,0)
    .leftEqualToView(self.timeLabel)
    .topSpaceToView(self.timeLabel, 0)
    .widthIs([UIScreen zj_screenWith] - 172 * [UIScreen zj_screenWScale]);
    
    
}


#pragma mark - 私有方法
- (void)setModel:(ShareOpenListModel *)model{
    _model = model;
    NSString *imageString;
    if (model.IMGJSON.count == 0) {
        imageString = @"11111";
    }else{
        imageString = model.IMGJSON[0][@"FILE_PATH"];
    }
    [self.actImageView sd_setImageWithURL:CREATEURL(imageString) placeholderImage:PlaceholderImage];
    NSString *start = [model.STARTTIME substringToIndex:5];
    NSString *end = [model.ENDTIME substringToIndex:5];
    self.timeLabel.text = [NSString stringWithFormat:@"有效期: %@-%@",start,end];
    
    self.actNumberLabel.text = [NSString stringWithFormat:@"发布者: %@",model.RESOURCE_PRINCIPAL];
    self.addressLabel.text = [NSString stringWithFormat:@"最大人数: %@",model.PEOPLE_NUM];

    if ([model.RESOURCETYPE isEqualToString:@"1"]) {
        self.statusLabel.text = @"场";
    }else{
        self.statusLabel.text = @"服";
    }
    self.actLabel.text = model.NAME;
    
}




#pragma mark - getter
- (UIImageView *)addressImageView{
    if (!_addressImageView) {
        _addressImageView = [UIImageView new];
        _addressImageView.contentMode = UIViewContentModeCenter;
        _addressImageView.image = [UIImage imageNamed:@"hdxq_address"];
    }
    return _addressImageView;
}


- (UIImageView *)timeImageVIew{
    if (!_timeImageVIew) {
        _timeImageVIew = [UIImageView new];
        _timeImageVIew.contentMode = UIViewContentModeCenter;
        _timeImageVIew.image = [UIImage imageNamed:@"hdxq_time"];
    }
    return _timeImageVIew;
}
- (UIImageView *)actImageView{
    if (!_actImageView) {
        _actImageView = [UIImageView new];
        _actImageView.contentMode = UIViewContentModeScaleAspectFill;
        _actImageView.clipsToBounds = YES;
    }
    return _actImageView;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        _timeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _timeLabel;
}

- (UILabel *)actNumberLabel{
    if (!_actNumberLabel) {
        _actNumberLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _actNumberLabel;
}


- (UILabel *)statusLabel{
    if (!_statusLabel) {
        _statusLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentCenter;
            label.numberOfLines = 2;
            label.textColor = [UIColor whiteColor];
            label.backgroundColor = [UIColor themeColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _statusLabel;
}

- (UILabel *)addressLabel{
    if (!_addressLabel) {
        _addressLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor lightGrayColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _addressLabel;
}

- (UILabel *)actLabel{
    if (!_actLabel) {
        _actLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.numberOfLines = 0;
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:15 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _actLabel;
}
- (UILabel *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor zj_colorWithHexString:@"f24141"];
            label.backgroundColor = [UIColor clearColor];
            label.font = [UIFont systemFontOfSize:13 * [UIScreen zj_textFontScale]];
            label;
        });
    }
    return _typeLabel;
}


@end
